rm(list = ls())################################################################################# Packageslibrary('tidyverse')library('reshape2')library('stringr')library('ggpmisc')################################################################################# Load data framesload('Data\df_Weekly_English.Rdata')load('Data\df_Weekly_Language_English.Rdata')load('data\df_Weekly_French.Rdata')load('df_Weekly_Language_French.Rdata')################################################################################vec_models <- c('IDENTITY_ATTACK',                 'INSULT',                 'PROFANITY',                 'THREAT',                'TOXICITY')df_Weekly_English <- df_Weekly_English %>%  select(all_of(c('Week', 'Party', vec_models)))df_Weekly_French <- df_Weekly_French %>%  select(all_of(c('Week', 'Party', vec_models)))df_Weekly <- merge(df_Weekly_English, df_Weekly_French, by = c('Week', 'Party')) %>%  na.omit() %>%  mutate_at(vars(c(paste(vec_models, '.x', sep = ''), paste(vec_models, '.y', sep = ''))),             function(x){1 / (1 + exp(-x))}) %>%  melt(id = c('Week', 'Party')) %>%  mutate(value = value * 100) %>%  mutate(Language = str_sub(variable, start = -1),         Language = case_when(Language == 'x' ~ 'English',                              Language == 'y' ~ 'French'),         variable = str_sub(variable, end = -3)) %>%  dcast(Week + Party + variable ~ Language) %>%  mutate(variable = str_replace_all(variable, '_', ' '))# Figure G2df_Weekly %>%   filter(Party != 'BQ') %>%  ggplot(mapping = aes(x = English, y = French)) +  facet_wrap(vars(variable), scales = 'free', nrow = 3) +  geom_abline(slope = 1, linetype = 'dashed') +  geom_point() +  stat_correlation(small.r = TRUE) +  theme_bw() +  labs(x = 'Estimates from English Models',       y = 'Estimates from French Models') +  xlim(0, NA) +  ylim(0, NA)ggsave('Correlation Weekly.pdf', width = 6.5, height = 8.5)# Figure G3df_Weekly %>%  filter(Party != 'BQ') %>%  ggplot(mapping = aes(x = English, y = French, group = Party, color = Party, shape = Party)) +  facet_wrap(vars(variable), scales = 'free', nrow = 3) +  geom_abline(slope = 1, linetype = 'dashed') +  geom_point() +  stat_correlation(vstep = 0.075, small.r = TRUE) +  scale_color_manual(values = c('blue', 'red', 'orange')) +  theme_bw() +  theme(legend.position = c(49/64, 1/7),        legend.justification = c(0.5, 0.5)) +  labs(x = 'Estimates from English Models',       y = 'Estimates from French Models') +  xlim(0, NA) +  ylim(0, NA)ggsave('Correlation Weekly by Party.pdf', width = 6.5, height = 8.5)################################################################################df_Weekly_Language_English <- df_Weekly_Language_English %>%  select(all_of(c('Week', 'Party', 'Language', vec_models)))df_Weekly_Language_French <- df_Weekly_Language_French %>%  select(all_of(c('Week', 'Party', 'Language', vec_models)))df_Weekly_Language <- merge(df_Weekly_Language_English, df_Weekly_Language_French, by = c('Week', 'Party', 'Language')) %>%  na.omit() %>%  mutate_at(vars(c(paste(vec_models, '.x', sep = ''), paste(vec_models, '.y', sep = ''))),             function(x){1 / (1 + exp(-x))}) %>%  melt(id = c('Week', 'Party', 'Language')) %>%  mutate(value = value * 100) %>%  mutate(Language.Analysis = str_sub(variable, start = -1),         Language.Analysis = case_when(Language.Analysis == 'x' ~ 'English',                                       Language.Analysis == 'y' ~ 'French'),         variable = str_sub(variable, end = -3)) %>%  dcast(Week + Party + Language + variable ~ Language.Analysis) %>%  mutate(variable = str_replace_all(variable, '_', ' '))# Figure G4df_Weekly_Language %>%   filter(Party != 'BQ') %>%  ggplot(mapping = aes(x = English, y = French)) +  facet_wrap(vars(variable), scales = 'free', nrow = 3) +  geom_abline(slope = 1, linetype = 'dashed') +  geom_point() +  stat_correlation(small.r = TRUE) +  theme_bw() +  labs(x = 'Estimates from English Models',       y = 'Estimates from French Models') +  xlim(0, NA) +  ylim(0, NA)ggsave('Correlation Weekly Language.pdf', width = 6.5, height = 8.5)# Figure G5df_Weekly_Language %>%   filter(Party != 'BQ') %>%  mutate(Language = case_when(Language == 'EN' ~ 'English',                              Language == 'FR' ~ 'French')) %>%  ggplot(mapping = aes(x = English, y = French, group = Language, color = Language, shape = Language)) +  facet_wrap(vars(variable), scales = 'free', nrow = 3) +  geom_abline(slope = 1, linetype = 'dashed') +  geom_point() +  stat_correlation(vstep = 0.075, small.r = TRUE) +  theme_bw() +  scale_color_grey() +  theme(legend.position = c(49/64, 1/7),        legend.justification = c(0.5, 0.5)) +  labs(x = 'Estimates from English Models',       y = 'Estimates from French Models') +  xlim(0, NA) +  ylim(0, NA)ggsave('Correlation Weekly Language by Language.pdf', width = 6.5, height = 8.5)